// @ts-ignore
import {expect} from 'chai'
import { IParams } from '../src/params';

describe('Docker Setup Function', () => {
    describe('handle legacy acr personal docker registry url', () => {
      it('should get public login address', async() => {
        let params = new IParams()
        params.region = 'cn-beijing'
        params.dockerRepository = 'registry.cn-beijing.aliyuncs.com/ns/repo'
        params.useVpcAddress = false

        expect(params.getLoginRegistry()).equal('registry.cn-beijing.aliyuncs.com')
      })

      it('should get vpc login address', () => {
        let params = new IParams()
        params.region = 'cn-beijing'
        params.dockerRepository = 'registry.cn-beijing.aliyuncs.com/ns/repo'
        params.useVpcAddress = true

        expect(params.getLoginRegistry()).equal('registry-vpc.cn-beijing.aliyuncs.com')
      })

      it('should get public image', () => {
        let params = new IParams()
        params.region = 'cn-beijing'
        params.dockerRepository = 'registry.cn-beijing.aliyuncs.com/ns/repo'
        params.useVpcAddress = false
        params.dockerTag = "1.0"

        expect(params.getPublicImage()).equal('registry.cn-beijing.aliyuncs.com/ns/repo:1.0')
      })

      it('should get vpc image', () => {
        let params = new IParams()
        params.region = 'cn-beijing'
        params.dockerRepository = 'registry.cn-beijing.aliyuncs.com/ns/repo'
        params.useVpcAddress = true
        params.dockerTag = "1.0"

        expect(params.getVpcImage()).equal('registry-vpc.cn-beijing.aliyuncs.com/ns/repo:1.0')
      })
    })

    describe('handle current acr personal docker registry url', () => {
      it('should get public login address', async() => {
        let params = new IParams()
        params.region = 'cn-hangzhou'
        params.dockerRepository = 'crpi-xxxxx.cn-hangzhou.personal.cr.aliyuncs.com/ns/repo'
        params.useVpcAddress = false

        expect(params.getLoginRegistry()).equal('crpi-xxxxx.cn-hangzhou.personal.cr.aliyuncs.com')
      })

      it('should get vpc login address', () => {
        let params = new IParams()
        params.region = 'cn-hangzhou'
        params.dockerRepository = 'crpi-xxxxx.cn-hangzhou.personal.cr.aliyuncs.com/ns/repo'
        params.useVpcAddress = true

        expect(params.getLoginRegistry()).equal('crpi-xxxxx-vpc.cn-hangzhou.personal.cr.aliyuncs.com')
      })

      it('should get public image', () => {
        let params = new IParams()
        params.region = 'cn-hangzhou'
        params.dockerRepository = 'crpi-xxxxx.cn-hangzhou.personal.cr.aliyuncs.com/ns/repo'
        params.useVpcAddress = false
        params.dockerTag = "1.0"

        expect(params.getPublicImage()).equal('crpi-xxxxx.cn-hangzhou.personal.cr.aliyuncs.com/ns/repo:1.0')
      })

      it('should get vpc image', () => {
        let params = new IParams()
        params.region = 'cn-hangzhou'
        params.dockerRepository = 'crpi-xxxxx.cn-hangzhou.personal.cr.aliyuncs.com/ns/repo'
        params.useVpcAddress = true
        params.dockerTag = "1.0"

        expect(params.getVpcImage()).equal('crpi-xxxxx-vpc.cn-hangzhou.personal.cr.aliyuncs.com/ns/repo:1.0')
      })
    })
});
